package A002lock8;

import java.util.concurrent.TimeUnit;

// 邮件新增暂停4秒钟的方法，请问先打印邮件还是短信？
// -----sendEmail
// -----sendSMS

class Phone02 {
    public synchronized void sendEmail() throws Exception {
        TimeUnit.SECONDS.sleep(4);
        System.out.println("-----sendEmail");
    }

    public synchronized void sendSMS() throws Exception {
        System.out.println("-----sendSMS");
    }

}


public class A002_线程八锁_2 {
    public static void main(String[] args) throws InterruptedException {

        Phone02 phone02 = new Phone02();

        new Thread(() -> {
            try {
                phone02.sendEmail();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "A").start();

        Thread.sleep(100);

        new Thread(() -> {
            try {
                phone02.sendSMS();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "B").start();
    }
}

